# coding=utf-8
'''
Created on 2013-12-23

@author: sunxiang
'''
import re
import tornado.escape
import time

from handler.base import BaseHandler

class ProfileHandler(BaseHandler):
    @tornado.web.authenticated
    def get(self, user, template_variables={}):
        if(re.match(r'[a-fA-F0-9]{32,32}', user)):
            user = self.userSerivice.get_user_by_uuid(user)
        else:
            user = self.userSerivice.get_user_by_username(user)
             
        if user:
             
            userinfo = tornado.escape.json_decode(user[0].to_json())
            profile = userinfo['profile']
            regtime = profile['regtime']
            timeobject= time.strptime(regtime,'%Y,%m,%d,%H,%M,%S,%f')
            timeformat = time.strftime("%Y-%m-%d", timeobject)
             
            template_variables["user_info"] = userinfo
            template_variables["reg_time"] = timeformat
 
            # TODO 查询主题、评论、收藏等
            self.render("user/profile.html", **template_variables)
